package com.yukh.test.javabase.collection.set;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class HashSetTest1 {
	class Name {
		private String first;
		private String last;

		public Name() {
		}

		public Name(String first, String last) {
			this.first = first;
			this.last = last;
		}

		public boolean equals(Object o) {
			if (this == o) {
				return true;
			}

			if (o.getClass() == Name.class) {
				Name n = (Name) o;
				return n.first.equals(first) && n.last.equals(last);
			}
			return false;
		}

		public int hashCode() {
			return first.hashCode()+last.hashCode();
		}

		public String toString() {
			return "Name[first=" + first + ", last=" + last + "]";
		}
	}

	private static void showSet(Set s) {
		Iterator it = s.iterator();
		while (it.hasNext()) {
			System.out.println(it.next().hashCode());
		}
	}

	public static void main(String[] args) {
		Set s = new HashSet();
		/*HashSetTest1 hst = new HashSetTest1();
		s.add(hst.new Name("abc", "123"));
		showSet(s);
		System.out.println(hst.new Name("abc", "123").hashCode());
		System.out.println(s.contains(hst.new Name("abc", "123")));*/
		
		s.add("1");
		s.add("1");
		s.add("1");
		s.add("1");
		
		Iterator it = s.iterator();
		while (it.hasNext()) {
		}
	}
}
